
import { imgcdn } from '@/utils/config.js'


export const imgUrls = (url) => {
  const reg = /^(http|https)/;
  if (!url) return;
  if (url.search(reg) != -1) return url;
  return imgcdn + url
}

export const validatePhone = (phoneNumber) => {
  const phoneRegex = /^1[3-9]\d{9}$/;
  return phoneRegex.test(phoneNumber);
}

export const debounce = (fn, delay) => {
  let timer = null;
  let isFirst = true;

  return function (...args) {
    if (timer) clearTimeout(timer);

    if (isFirst) {
      fn.apply(this, args);
      isFirst = false;
      return;
    }

    timer = setTimeout(() => {
      fn.apply(this, args);
    }, delay);
  }
}